<%-- 
    Document   : registerAction
    Created on : 2021-12-14, 23:31:19
    Author     : Mayiyaheila
--%>

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="Vo.User"%>
<%@page import="Dao.UserDao"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
    <%
        request.setCharacterEncoding("gb2312");
        String uid = request.getParameter("Uid");
        String password = request.getParameter("password");
        String cpassword = request.getParameter("cpassword");
        String username = request.getParameter("username");
        UserDao udao = new UserDao();
        User user = null;
        try {
            user = udao.getUserByAccount(uid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (user!=null) {
        request.setAttribute("accountMess", "该用户已被注册");
        request.getRequestDispatcher("register.jsp").forward(request, response);
        }
        else{
        if (!password.equals(cpassword)) {
        request.setAttribute("imageMess", "两次密码输入不一致!");
        request.getRequestDispatcher("register.jsp").forward(request, response);
        }

        if (!password.equals(cpassword)) {
        request.setAttribute("imageMess", "两次密码输入不一致!");
        request.getRequestDispatcher("register.jsp").forward(request, response);
        }
        else {

        boolean flag = udao.register(uid, password, username);

        if (!flag) {%>
    注册失败。<a href="register.jsp">请重试</a>
    <%}
        else{%>
    <div style="text-align:center">
        注册成功,<a href="login.jsp">前往登录页面</a>
    </div>
    <%}
        }}%>

    </body>
</html>
